package com.michael.study.arouter.base;

import android.app.Application;
import android.util.Log;

import com.alibaba.android.arouter.launcher.ARouter;
import com.michael.study.arouter.network.ARouteApi;
import com.michael.study.library.BuildConfig;
import com.michael.study.library.base.AppInfo;
import com.michael.study.library.base.BaseAppInit;
import com.michael.study.library.base.ModuleConfig;

/**
 * Description:
 *
 * <p>Created by liuguoquan on 2020/8/5 09:45.
 */
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        ARouter.openDebug();
        ARouter.openLog();
        ARouter.init(this);
        Log.d("lgq", "App onCreate: ");
        AppInfo.getInstance().init(BuildConfig.DEBUG);
        ARouteApi.init(new ARouteNetWorkInfo());
        ARouteApi.getInstance();
        initHighPriority(this);
        initLowPriority(this);
    }

    public void initHighPriority(Application application) {
        for (String moduleInit : ModuleConfig.moduleInits) {
            try {
                Class<?> clazz = Class.forName(moduleInit);
                BaseAppInit appInit = (BaseAppInit) clazz.newInstance();
                appInit.onInitHighPriority(application);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }
    }

    public void initLowPriority(Application application) {
        for (String moduleInit : ModuleConfig.moduleInits) {
            try {
                Class<?> clazz = Class.forName(moduleInit);
                BaseAppInit appInit = (BaseAppInit) clazz.newInstance();
                appInit.onInitLowPriority(application);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }
    }
}
